package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.business.BusinessListDO;
import com.qk.dto.business.BusinessDTO;
import com.qk.dto.business.BusinessFollowDTO;
import com.qk.dto.business.BusinessListDTO;
import com.qk.dto.business.BusinessPoolListDTO;
import com.qk.entity.Business;
import com.qk.management.service.BusinessService;
import com.qk.vo.business.BusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * &#064;author：zzq
 * &#064;createTime：2025/10/15 10:54
 * &#064;description： 商机跟进controller
 */
@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    //新增商机接口
    @PostMapping
    public Result addBusiness(@RequestBody BusinessDTO dto) {
        businessService.addBusiness(dto);
        return Result.success();
    }
    //根据列表查询商机
    @GetMapping
    public Result businessList(BusinessListDTO dto) {
        PageResult<BusinessListDO> pageResult = businessService.businessList(dto);
        return Result.success(pageResult);
    }
    //根据id查询商机
    @GetMapping("/{id}")
    public Result getBusinessById(@PathVariable Integer id) {
        BusinessVO vo= businessService.getBusinessInfoById(id);
        return Result.success(vo);
    }
    //分配商机
    @PutMapping("/assign/{businessId}/{userId}")
    public Result distributeBusiness(@PathVariable Integer businessId, @PathVariable Integer userId) {
        businessService.distributeBusiness(businessId, userId);
        return Result.success();
    }
    //跟进商机
    @PutMapping
    public Result followUpBusiness(@RequestBody BusinessFollowDTO dto) {
        businessService.followUpBusiness(dto);
        return Result.success();
    }
    //踢回公海
    @PutMapping("/back/{id}")
    public Result backToPool(@PathVariable Integer id) {
        businessService.backToPool(id);
        return Result.success();
    }
    //商机转客户
    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id) {
        businessService.toCustomer(id);
        return Result.success();
    }
    //公海池列表查询
    @GetMapping("/pool")
    public Result businessPoolList(BusinessPoolListDTO dto) {
        PageResult<Business> pageResult = businessService.businessPoolList(dto);
        return Result.success(pageResult);
    }
}
